package com.etoak.web.sys_menu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.etoak.web.sys_menu.entity.AssignTreeParm;
import com.etoak.web.sys_menu.entity.AssignTreeVo;
import com.etoak.web.sys_menu.entity.MakeMenuTree;
import com.etoak.web.sys_menu.entity.SysMenu;
import com.etoak.web.sys_menu.mapper.SysMenuMapper;
import com.etoak.web.sys_menu.service.SysMenuService;
import com.etoak.web.sys_user.entity.SysUser;
import com.etoak.web.sys_user.service.SysUserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @Author by 孙有泽
 * @Date 2025/2/20 16:50
 * @Description
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {

    @Autowired
    private SysMenuMapper sysMenuMapper;

    @Autowired
    private SysUserService sysUserService;
    @Override
    public List<SysMenu> getParent() {
        Integer[] type={0,1};
        List<Integer> list = Arrays.asList(type);
        QueryWrapper<SysMenu> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.lambda().in(SysMenu::getType,list).orderByAsc(SysMenu::getSort);

        List<SysMenu> sysMenus = this.baseMapper.selectList(objectQueryWrapper);
        System.out.println(sysMenus);
        SysMenu sysMenu = new SysMenu();
        sysMenu.setTitle("顶级菜单");
        sysMenu.setLabel("顶级菜单");
        sysMenu.setId("0");
        sysMenu.setPid("-1");
        sysMenu.setValue("0");
        sysMenus.add(sysMenu);
        List<SysMenu> tree = MakeMenuTree.makeTree(sysMenus, "-1");
        return tree;
    }

    @Override
    public List<SysMenu> queryMenuByUserId(String userId) {
        return this.sysMenuMapper.queryMenuByUserId(userId);
    }

    @Override
    public List<SysMenu> queryMenuByRoleId(String roleId) {
        return this.sysMenuMapper.queryMenuByRoleId(roleId);
    }


}
